const SalaryInput = (val, intLength, decimalLength, format) => {
    let newVal = val
        .toString()
        .replace(/[^\d.]/g, '')
        .replace(/\.{2,}/g, '.')
        .replace(/^\./g, '')
        .replace('.', '$#$')
        .replace(/\./g, '')
        .replace('$#$', '.');
    const formatNewVal = newVal.split('.');
    if (formatNewVal.length === 2) {
        let intVal = newVal.split('.')[0];
        let decimalVal = newVal.split('.')[1];
        if (intVal.length > intLength) {
            intVal = intVal.substring(0, intLength);
        }
        if (decimalVal.length > decimalLength) {
            decimalVal = decimalVal?.substring(0, decimalLength);
        }
        newVal = `${intVal}.${decimalVal}`;
    } else {
        newVal = newVal.substring(0, intLength);
    }
    if (format) {
        newVal = String(newVal ?? '').replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    }
    return newVal;
};
const SalaryYearInput = (val = 1, format) => {
    if (val) {
        return SalaryInput(val, 12, 8, format);
    }
    return '';
};
const SalaryMonthInput = (val = 1, format) => {
    if (val) {
        return SalaryInput(val, 8, 4, format);
    }
    return '';
};

export { SalaryYearInput as default, SalaryYearInput, SalaryMonthInput };
